<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品名称" prop="jrProductName">
        <el-input
          v-model="queryParams.jrProductName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="资金提供方" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入资金提供方"
          clearable
          @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="申请类型">
        <el-select v-model="queryParams.jrProductType" placeholder="请选择">
          <el-option value="">请选择</el-option>
          <el-option label="租房分期" value="1"></el-option>
          <el-option label="收房贷" value="2"></el-option>
          <el-option label="应收租约保理" value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['finance:product:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['finance:product:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['finance:product:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['finance:product:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="productList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主键 自增" align="center" prop="id"/>
      <el-table-column label="产品名称" align="center" prop="jrProductName"/>
      <el-table-column label="资方信息ID" align="center" prop="companyId"/>
      <el-table-column label="资金提供方" align="center" prop="companyName"/>
      <el-table-column label="分期期限" align="center" prop="instalmentPeriod">
      </el-table-column>
      <el-table-column label="授信额度" align="center" prop="creditLine"/>
      <el-table-column label="金融产品类型" align="center" prop="jrProductType">
        <template slot-scope="scope">
          <span v-if="scope.row.jrProductType==1">租房分期</span>
          <span v-if="scope.row.jrProductType==2">收房贷</span>
          <span v-if="scope.row.jrProductType==3">应收租约保理</span>
        </template>
      </el-table-column>
      <el-table-column label="还款方式" align="center" prop="repaymentType" >
        <template slot-scope="scope">
          <span v-if="scope.row.repaymentType==1">按月还款</span>
          <span v-if="scope.row.repaymentType==2">按季还款</span>
          <span v-if="scope.row.repaymentType==3">按租约周期支付</span>
        </template>
      </el-table-column>

      <el-table-column label="银行账户类型" align="center" prop="accountType"/>
      <el-table-column label="银行卡号" align="center" prop="bankCardNumber"/>
      <el-table-column label="开户银行ID" align="center" prop="bankId"/>
      <el-table-column label="银行名称" align="center" prop="bankName"/>
      <el-table-column label="开户行(支行)" align="center" prop="openingBank"/>
      <el-table-column label="账户名称" align="center" prop="accountName"/>
      <el-table-column label="联行行号" align="center" prop="bankBranchCodeLh"/>
      <el-table-column label="开户行所在省ID" align="center" prop="bankAccountProvince"/>
      <el-table-column label="申请条件" align="center" prop="applicationConditions"/>
      <el-table-column label="风控要求" align="center" prop="riskRequirement"/>
      <el-table-column label="创建用户ID" align="center" prop="createUserid"/>
      <el-table-column label="更新用户ID" align="center" prop="updateUserid"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['finance:product:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['finance:product:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改金融产品对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="产品名称" prop="jrProductName">
          <el-input v-model="form.jrProductName" placeholder="请输入产品名称"/>
        </el-form-item>
        <el-form-item label="资方信息ID" prop="companyId">
          <el-input v-model="form.companyId" placeholder="请输入资方信息ID"/>
        </el-form-item>
        <el-form-item label="资金提供方" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入资金提供方"/>
        </el-form-item>
        <el-form-item label="分期期限(-1表示无限期)" prop="instalmentPeriod">
          <el-input v-model="form.instalmentPeriod" placeholder="请输入分期期限(-1表示无限期)"/>
        </el-form-item>
        <el-form-item label="授信额度(单位：%，比如80%，存的是80)" prop="creditLine">
          <el-input v-model="form.creditLine" placeholder="请输入授信额度(单位：%，比如80%，存的是80)"/>
        </el-form-item>
        <el-form-item label="支付PC链接(URL)" prop="urlPayPc">
          <el-input v-model="form.urlPayPc" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="支付移动链接(URL)" prop="urlPayMoble">
          <el-input v-model="form.urlPayMoble" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="补全信息PC(URL)" prop="urlAddDetailInfoPc">
          <el-input v-model="form.urlAddDetailInfoPc" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="补全信息移动(URL)" prop="urlAddDetailInfoMobile">
          <el-input v-model="form.urlAddDetailInfoMobile" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="App下载(URL)" prop="urlAppDownload">
          <el-input v-model="form.urlAppDownload" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCardNumber">
          <el-input v-model="form.bankCardNumber" placeholder="请输入银行卡号"/>
        </el-form-item>
        <el-form-item label="开户银行ID" prop="bankId">
          <el-input v-model="form.bankId" placeholder="请输入开户银行ID"/>
        </el-form-item>
        <el-form-item label="银行名称" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入银行名称"/>
        </el-form-item>
        <el-form-item label="开户行(支行)" prop="openingBank">
          <el-input v-model="form.openingBank" placeholder="请输入开户行(支行)"/>
        </el-form-item>
        <el-form-item label="账户名称" prop="accountName">
          <el-input v-model="form.accountName" placeholder="请输入账户名称"/>
        </el-form-item>
        <el-form-item label="联行行号" prop="bankBranchCodeLh">
          <el-input v-model="form.bankBranchCodeLh" placeholder="请输入联行行号"/>
        </el-form-item>
        <el-form-item label="开户行所在省ID" prop="bankAccountProvince">
          <el-input v-model="form.bankAccountProvince" placeholder="请输入开户行所在省ID"/>
        </el-form-item>
        <el-form-item label="申请条件" prop="applicationConditions">
          <el-input v-model="form.applicationConditions" placeholder="请输入申请条件"/>
        </el-form-item>
        <el-form-item label="风控要求" prop="riskRequirement">
          <el-input v-model="form.riskRequirement" placeholder="请输入风控要求"/>
        </el-form-item>
        <el-form-item label="删除标识
,0:未删除，1：删除" prop="delFlg">
          <el-input v-model="form.delFlg" placeholder="请输入删除标识
,0:未删除，1：删除"/>
        </el-form-item>
        <el-form-item label="创建用户ID" prop="createUserid">
          <el-input v-model="form.createUserid" placeholder="请输入创建用户ID"/>
        </el-form-item>
        <el-form-item label="更新用户ID" prop="updateUserid">
          <el-input v-model="form.updateUserid" placeholder="请输入更新用户ID"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {listProduct, getProduct, delProduct, addProduct, updateProduct} from "@/api/finance/product";

  export default {
    name: "Product",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 金融产品表格数据
        productList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          jrProductName: null,
          companyId: null,
          companyName: null,
          instalmentPeriod: null,
          creditLine: null,
          jrProductType: null,
          repaymentType: null,
          urlPayPc: null,
          urlPayMoble: null,
          urlAddDetailInfoPc: null,
          urlAddDetailInfoMobile: null,
          urlAppDownload: null,
          accountType: null,
          bankCardNumber: null,
          bankId: null,
          bankName: null,
          openingBank: null,
          accountName: null,
          bankBranchCodeLh: null,
          bankAccountProvince: null,
          applicationConditions: null,
          riskRequirement: null,
          delFlg: null,
          createUserid: null,
          updateUserid: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          jrProductName: [
            {required: true, message: "产品名称不能为空", trigger: "blur"}
          ],
          companyName: [
            {required: true, message: "资金提供方不能为空", trigger: "blur"}
          ],
          jrProductType: [
            {
              required: true, message: "金融产品类型,1:租房分期,2:收房贷,3:应收租约保理,不能为空",
              trigger:"change"
    }
    ],
      repaymentType: [
        {
          required: true, message: "还款方式,1:按月还款,2:按季还款3:按租约周期支付,不能为空",
          trigger:"change"
    }
    ],
      delFlg: [
        {
          required: true, message: "删除标识, 0: 未删除，1：删除不能为空",
          trigger: "blur"
        }
    ],
      createUserid: [
        {required: true, message: "创建用户ID不能为空", trigger: "blur"}
      ],
      createTime:
      [
        {required: true, message: "创建时间不能为空", trigger: "blur"}
      ],
        updateUserid:
      [
        {required: true, message: "更新用户ID不能为空", trigger: "blur"}
      ],
       updateTime:
      [
        {required: true, message: "更新时间不能为空", trigger: "blur"}
      ]
    }
    }
      ;
    },
      created()
      {
        this.getList();
      }
    ,
      methods: {
        /** 查询金融产品列表 */
        getList()
        {
          this.loading = true;
          listProduct(this.queryParams).then(response => {
            this.productList = response.rows;
            this.total = response.total;
            this.loading = false;
          });
        }
      ,
        // 取消按钮
        cancel()
        {
          this.open = false;
          this.reset();
        }
      ,
        // 表单重置
        reset()
        {
          this.form = {
            id: null,
            jrProductName: null,
            companyId: null,
            companyName: null,
            instalmentPeriod: null,
            creditLine: null,
            jrProductType: null,
            repaymentType: null,
            urlPayPc: null,
            urlPayMoble: null,
            urlAddDetailInfoPc: null,
            urlAddDetailInfoMobile: null,
            urlAppDownload: null,
            accountType: null,
            bankCardNumber: null,
            bankId: null,
            bankName: null,
            openingBank: null,
            accountName: null,
            bankBranchCodeLh: null,
            bankAccountProvince: null,
            applicationConditions: null,
            riskRequirement: null,
            delFlg: null,
            createUserid: null,
            createTime: null,
            updateUserid: null,
            updateTime: null
          };
          this.resetForm("form");
        }
      ,
        /** 搜索按钮操作 */
        handleQuery()
        {
          this.queryParams.pageNum = 1;
          this.getList();
        }
      ,
        /** 重置按钮操作 */
        resetQuery()
        {
          this.resetForm("queryForm");
          this.handleQuery();
        }
      ,
        // 多选框选中数据
        handleSelectionChange(selection)
        {
          this.ids = selection.map(item => item.id)
          this.single = selection.length !== 1
          this.multiple = !selection.length
        }
      ,
        /** 新增按钮操作 */
        handleAdd()
        {
          this.$router.push("/finance/product/add")
        }
      ,
        /** 修改按钮操作 */
        handleUpdate(row)
        {
          this.reset();
          const id = row.id || this.ids
          getProduct(id).then(response => {
            this.form = response.data;
            this.open = true;
            this.title = "修改金融产品";
          });
        }
      ,
        /** 提交按钮 */
        submitForm()
        {
          this.$refs["form"].validate(valid => {
            if (valid) {
              if (this.form.id != null) {
                updateProduct(this.form).then(response => {
                  this.$modal.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                });
              } else {
                addProduct(this.form).then(response => {
                  this.$modal.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                });
              }
            }
          });
        }
      ,
        /** 删除按钮操作 */
        handleDelete(row)
        {
          const ids = row.id || this.ids;
          this.$modal.confirm('是否确认删除金融产品编号为"' + ids + '"的数据项？').then(function () {
            return delProduct(ids);
          }).then(() => {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          }).catch(() => {
          });
        }
      ,
        /** 导出按钮操作 */
        handleExport()
        {
          this.download('finance/finance/export', {
            ...this.queryParams
          }, `product_${new Date().getTime()}.xlsx`)
        }
      }
    };
</script>
